# -*- coding: utf-8 -*-
"""
Created on Sat Jul 13 19:03:26 2019

@author: Lee
"""
import requests
import random
from bs4 import BeautifulSoup
import json
import execjs


class Book(object):
    
    def __init__(self,bookid):
        self.headers={'User-Agent':random.choice(user_agent)}
        self.bookid=bookid
        self.book_url='https://www.aliwx.com.cn/reader?bid={}'.format(self.bookid)
        self.chapter_url='https://c13.shuqireader.com/pcapi/chapter/contentfree/'

    
    def get_json(self):
        
        r=requests.get(self.book_url,headers=self.headers)
        soup=BeautifulSoup(r.text, 'html.parser')
        info=soup.find('i', {'class': 'page-data js-dataChapters'}).get_text()
        return json.loads(info)
    
    def parse_info(self, book_info):

        bookName=book_info['bookName']
        authorName=book_info['authorName']
        chapterNum=book_info['chapterNum']
        wordCount=book_info['wordCount']
        contentUrl=book_info['contentUrl']
        book_data={
            'bookName': bookName,
            'authorName': authorName,
            'chapterNum': chapterNum,
            'wordCount': wordCount,
            'contentUrl': contentUrl,
        }
        print(book_data)
        chapters=book_info['chapterList'][0]['volumeList']
        chapter_list=[]
        for chapter in chapters:
            chapterName=chapter['chapterName']
            chapterPrice=chapter['chapterPrice']
            chapterUrlSuffix=chapter['contUrlSuffix']
            chapter_data={
                'chapterName': chapterName,
                'chapterPrice': chapterPrice,
                'chapterUrlSuffix': chapterUrlSuffix
            }
            chapter_list.append(chapter_data)
        return chapter_list,bookName
    
    def get_content(self, chapterUrlSuffix):

        url=self.chapter_url + chapterUrlSuffix
        r=requests.get(url,headers=self.headers).json()
        if r['message']=="success":
            return r['ChapterContent']
        else:
            print(r['message'])
            return False

def get_bookid(bookname):
    
    book_list=[{'小小娇妻甜蜜蜜': '7939173'}, {'萌宝契约：总裁爹地，霸道宠！': '7947334'}, {'末代宗师': '7950992'}, {'花式追妻：老婆大人有点冷': '7909255'}, {'花都超品医圣': '7888007'}, {'重生之都市狂尊': '7842508'}, {'噬天至尊': '7918072'}, {'一品狂婿': '7948682'}, {'剑网画长安': '7808140'}, {'成风破道': '7801408'}, {'荡魔志': '7795120'}, {'超神覆甲': '7937867'}, {'最强都市魔尊': '7887225'}, {'时空至尊': '7771009'}, {'重生修真赘婿': '7935486'}, {'重生九零美好家园': '7927703'}, {'穿越九零：福妻好运来': '7869633'}, {'乡村透视仙医': '7666965'}, {'春闺艳史：风流督公盛宠妻': '7926785'}, {'落日楼兰': '7659798'}, {'夜入枭林': '7832632'}, {'石破惊仙': '7740251'}, {'情陷高跟鞋': '7951997'}, {'不灭元尊': '7395972'}, {'至尊妖神': '7711213'}, {'重生九零：鲜妻甜似火': '7866784'}, {'末日之全球流感': '7733923'}, {'盛世宠后：竹马戏青梅': '7859093'}, {'透视小神农': '6607287'}, {'大梁诡案录': '7909838'}, {'洪荒神帝': '6813935'}, {'重生大富翁': '7460830'}, {'天降财运': '7945765'}, {'替嫁小狂妃：邪魅鬼王难驯服！': '7067719'}, {'都市弃少兵王': '7905727'}, {'绝世丹尊': '7903381'}, {'良田宝妻：冲喜小农女': '7929854'}, {'绝品小神农': '6952591'}, {'重生八零之小小农家女': '7499281'}, {'汉宫秋': '7068320'}, {'乡村小邪医': '7933656'}, {'重生悍妻：智障老公别装纯': '7905404'}, {'都市邪兵': '7865348'}, {'天价小萌妻：试婚老公超给力': '7739390'}, {'兰陵行歌': '7953916'}, {'弑妖传': '7933696'}, {'凡尘星神传': '7944524'}, {'我的极品女鬼老婆': '7896736'}, {'逆天之主': '7713651'}, {'诸天战帝': '7725121'}, {'绝世仙王闯花都': '7858390'}, {'星空道尊': '7405890'}, {'古陵夜行': '7953942'}, {'七号客栈': '7953965'}, {'君心似我心': '7953560'}, {'来自平行宇宙的养猫人': '7896664'}, {'重生之都市金仙': '7813258'}, {'绝世医尊': '7947956'}, {'农家之继室难为': '7912945'}, {'惊世灵师：废材五小姐': '7357813'}, {'农门娇后': '7826013'}, {'都市之兵王归来': '6852955'}, {'江湖志': '7906243'}, {'世子轻狂，太傅撩人': '7834499'}, {'重生八零:财源广进': '7660566'}, {'算死命': '7944766'}, {'两钱捉妖师': '7849500'}, {'重生之都市弃少': '7864932'}, {'一不小心变女神': '7903720'}, {'重生空间：王牌千金': '7786671'}, {'绝色异眸': '7806540'}, {'豪门蜜恋，总裁大人好傲娇': '7875950'}, {'极品之桃运神农': '7858559'}, {'庶女攻略：废柴王妃有点狂': '7945096'}, {'爱的回旋踢': '7808775'}, {'血宋': '7696387'}, {'蜜爱100分：总裁，放肆宠': '7906753'}, {'绝密档案': '7842883'}, {'农家小彪妻': '7414591'}, {'司律有温情': '7899202'}, {'重回六零：种田发家养崽崽': '7896571'}, {'萌宝来袭：总裁爹地快投降': '7830550'}, {'独家宠爱：爹地，宠上天！': '7858336'}, {'血月': '7946729'}, {'都市共享男神系统': '7937246'}, {'重生八零之娇妻的逆袭': '7885355'}, {'最强赘婿': '7923423'}, {'巫道诡事': '7917892'}, {'逐鼎九州': '7740075'}, {'都市兵锋': '6854363'}, {'大胤王朝': '7867843'}, {'极品偷香村医': '7797230'}, {'都市极品透视狂少': '7900077'}, {'重生九零逆袭小首富': '7891158'}, {'庶女穿越手札': '7948158'}, {'万古至尊': '7693298'}, {'村野小圣医': '7526319'}, {'鬼眼鉴宝师': '7899167'}, {'总裁夫人坏得很': '7854566'}, {'都市最强狂兵': '7898674'}, {'他的声音很撩': '7935049'}, {'你是我的少年': '7925093'}, {'只对你有感觉': '7835055'}, {'桃运小村医': '7651455'}, {'校园超级兵王': '7794724'}, {'乡村超级医圣': '7146755'}, {'薛小苒的古代搭伙之旅': '7884683'}, {'神坑空间：邪王爆宠小农女': '7439973'}, {'重生之仙尊赘婿': '7948511'}, {'妖孽小春医': '7947704'}, {'明末之力挽狂澜': '7808943'}, {'大明长歌': '7445381'}, {'都市妙手狂医': '7927560'}, {'错爱娇妻：双生总裁轻点宠': '7821750'}, {'半欢半爱：戏精总裁赖上身': '7858671'}, {'通冥鬼记': '7792290'}, {'重生之都市仙王': '7948558'}, {'重生九零致富记': '7473199'}, {'豪门蜜宠:小妻撩夫正张狂': '7902957'}, {'穿越之兽世种田记': '7119057'}, {'天道至尊': '7811949'}, {'出枪者': '7809954'}, {'史上最狂妖帝': '7913095'}, {'我从古墓来': '7471695'}, {'摄政王的农家媳': '7659945'}, {'建章九重': '7953436'}, {'拐个将军来发家': '7089575'}, {'神医狂妃：冷面将军绕指柔': '7835026'}, {'修仙两万年归来': '7826008'}, {'极宠嚣妻：我的女人谁敢动': '7910269'}, {'家有饿郎：囤粮种田好悠闲': '7937135'}, {'杀人麻烦预个约': '7950094'}, {'天才药剂师': '7902814'}, {'霸道男神：独宠小甜心': '7830553'}, {'鬼术大宗师': '7031453'}, {'美女总裁的神级高手': '7850442'}, {'惟愿月华独照君': '7876507'}, {'谭少独宠律政前妻': '7792592'}, {'万古丹尊': '7916734'}, {'农门小辣妻': '7418924'}, {'农门巧厨娘': '7821841'}, {'霍总，夫人又上热搜啦！': '7935272'}, {'男友总想飞走': '7847452'}, {'暗夜销婚：总裁，别想逃': '7869651'}, {'都市最强赘婿': '7917033'}, {'贴身狂少': '7032364'}, {'女总裁的贴身赘婿': '7947923'}, {'娇妻撩人：陆少心尖宠': '7859003'}, {'都市之极品赘婿': '7953023'}, {'医仙纵横': '7928033'}, {'重生八零：麻辣小媳妇': '7739391'}, {'农门医女：将军的小甜妻': '7899640'}, {'都市之全能兵王': '7727259'}, {'普天Ⅰ乱世异族': '7954147'}, {'重生九零之麻辣小鲜妻': '7502547'}, {'万古神主': '7899089'}, {'丝路大亨': '7157158'}, {'功德印': '7446688'}, {'星海大迁徙': '7816244'}, {'大道无边': '7446444'}, {'农门医妃：小娘子致富路': '7847464'}, {'他偷走了我们的时间': '7816957'}, {'大汉王朝': '7352398'}, {'大佬请让我活下去': '7948562'}, {'未来武神': '7078062'}, {'剑逆诸天': '7067742'}, {'风少的霸王花悍妻': '7889887'}, {'王爷，侧妃要爬墙': '7634396'}, {'总裁的专职饲养员': '7809701'}, {'娇妻难为：总裁太缠人': '7851240'}, {'农门俏娘子：捡个郎君生个娃': '7850771'}, {'女神的全能高手': '7925067'}, {'绝才天下：腹黑战神妃': '7953557'}, {'诛天无双': '7823297'}, {'镇魂商店': '7898963'}, {'农女致富：种田赚钱撩夫忙': '7718434'}, {'逆天神尊': '7933644'}, {'荒唐活宝传': '7526975'}, {'婚色撩人：司医生，多多指教': '7894782'}, {'冰山总裁的奶爸兵王': '7887162'}, {'重生之无敌仙君': '7111687'}, {'私房蜜语：娇妻你不乖': '6960463'}, {'乡村神仙代购': '7949408'}, {'穿越兽世：小巫娘，生崽崽': '7792069'}, {'神魔传': '7841047'}, {'农门丑妇': '6841674'}, {'都市无双狂兵': '7691996'}, {'我的绝色总裁未婚妻': '6725806'}, {'情敌总是不小心围绕左右': '7855565'}, {'德狂侠女': '289903'}, {'罹仙': '7503090'}, {'攻略那个腹黑王爷': '7902364'}, {'弃妇重生：医品凰后要独宠': '7941859'}, {'傲世天帝': '7867052'}, {'上仙，入赘吗？': '7899252'}, {'夺魄铭情': '7952593'}, {'圣月之都': '7910992'}, {'神仙改造营': '7861980'}, {'寂灭道尊': '7953940'}, {'医品赘婿': '7935489'}, {'大明峥嵘': '7917217'}, {'逆天狂仙': '7834968'}, {'黄河诡棺': '7916588'}, {'影后进化论': '7903059'}, {'田园小富婆：夫君快到碗里来': '7923067'}, {'施家邪子': '7825287'}, {'江湖七宗罪': '7789826'}, {'异界大富豪': '7923855'}, {'恶魔大领主': '7801911'}, {'绝世战灵': '7846390'}, {'王牌御师': '7948761'}, {'我的男友品种特殊': '7938279'}, {'诡术神医': '7935107'}, {'夜寒香：邪王的绝世宠妃': '7871575'}, {'邪王爱补刀：王妃别打脸': '7900075'}, {'诡域：绝密救援': '7854565'}, {'龙魂武尊': '7850289'}, {'农门女儿香': '7861305'}, {'银翼之殇': '7866594'}, {'我的世界之大明星': '7953554'}, {'重生之都市邪皇': '7929802'}, {'盖世天魔': '7849493'}, {'农家小辣妻，夫君种田去': '7858732'}, {'总裁的甜宠娇妻': '7850320'}, {'王者农民工': '7785660'}, {'我可能修的是假仙': '7502070'}, {'太古狂魔': '6720460'}, {'龙魂剑尊': '7928075'}, {'凌霄剑主': '7659639'}, {'国师在上，种田小福妻': '7838998'}, {'冷王嫡妃不下堂': '7892837'}, {'盛世甜宠：总裁的头号萌妻': '7927004'}, {'星际拓展指南': '7951928'}, {'通天神尊': '7918327'}, {'太古剑圣': '7899257'}, {'软萌甜心：腹黑总裁太宠我': '7913757'}, {'重生八零之全能小娇妻': '7910126'}, {'重生八零：致富虐渣奔小康': '7851810'}, {'古圣': '7681231'}, {'彪悍农家小娘子': '7867660'}, {'女总裁的近身狂兵': '7900215'}, {'鬼谷奇门赘婿': '7945113'}, {'超级赘婿系统': '7941386'}, {'我的绝色妖孽室友': '7874345'}, {'农门蟹后': '7032221'}, {'绝世皇龙': '7909837'}, {'我是富家子': '7941383'}, {'超级农民': '7808074'}, {'古村诡事': '7859201'}, {'饿郎缠身：买个娘子生娃子': '7672382'}, {'农女重生之丞相夫人': '6912651'}, {'送葬诡事': '7885981'}, {'乡野大富翁': '7934400'}, {'重生最毒嫡女': '7792840'}, {'乡村超品神医': '7691400'}, {'龙玄神帝': '7837298'}, {'全民异能时代': '7947938'}, {'太古龙帝': '7849494'}, {'逆天神医': '6900908'}, {'美女总裁的贴身兵王': '7396477'}, {'农门悍妻：我娘子超凶': '7862716'}, {'绝世魔帝': '7801476'}, {'都市全能赘婿': '7948148'}, {'穿到首辅黑化前': '7667984'}, {'神级富豪': '7938571'}, {'农女成凤，步步为营': '7783883'}, {'铁血炎龙': '7750963'}, {'至尊骨帝': '7526242'}, {'重生八零小甜妻': '7821331'}, {'嫡女攻略：谋个王爷好上位': '7850800'}, {'太古魔神': '7862317'}, {'昭云奇剑录': '7381997'}, {'宝妻如珠的悠闲日子': '7842016'}, {'超能兵王': '7883979'}, {'倾城狂妻，爬墙皇后不好追': '7875379'}, {'进化帝国': '7783159'}, {'超凡透视': '7027359'}, {'都市之最强仙尊': '7947925'}, {'妇科小神医': '7452313'}, {'网游之不灭魔体': '7941074'}, {'每天都在帮道友历劫': '7850436'}, {'极品小医圣': '7929971'}, {'重生八零  小媳妇撩夫忙': '7866421'}, {'九密之璇玑鉴': '7909349'}, {'福来孕转：农门商女有灵泉': '7795889'}, {'重生九零，学霸小富妞': '7483568'}, {'一世狂兵': '7905488'}, {'都市仙医圣手': '7860985'}, {'农女神医：夫君要听话': '7513467'}, {'女镇长的贴身兵王': '7070142'}, {'废柴成神：妖孽，你跪下': '7085142'}, {'都市逆天神尊': '7902677'}, {'重生七零致富记': '7785765'}, {'嫡女凤命：双面侯爷太腹黑': '7888025'}, {'农家小厨：空间有锦鲤': '7736484'}, {'庶女掌家手册': '7892934'}, {'鉴宝神师': '7869653'}, {'狂野小神医': '7825141'}, {'火焰': '7943714'}, {'最拽女婿': '7933614'}, {'农家俏媳妇：养夫带娃种田忙': '7690939'}, {'报告老板，夫人又掉线了': '7944889'}, {'一品兵王': '7691769'}, {'重生七零之悠闲人生': '7940413'}, {'重生之豪门千金太难撩': '7924799'}, {'极品大富翁': '7938535'}, {'桃运狂医': '7888257'}, {'戏精王妃': '7867835'}, {'重返八零好时光': '7926786'}, {'都市之妖尊归来': '7924523'}, {'我在异界老装逼': '7948143'}, {'这个少年很危险': '7929251'}, {'烈焰狂兵在都市': '7949418'}, {'乡村小药王': '7837716'}, {'相府千金：谋妃定天下': '7787177'}, {'还尸匠': '7949136'}, {'一品狂兵': '7918058'}, {'极品村医': '7899745'}, {'爷！我想翻身做主人': '7847007'}, {'神瑛小厨娘：美食天下': '7948166'}, {'应国公府秘闻录：夫君娶了个球': '7865231'}, {'绝代神帝': '7944372'}, {'偷香小农民': '7812821'}, {'至尊富二代': '7938567'}, {'乡村最强医仙': '7898133'}, {'重生之武魂至尊': '7424384'}, {'乱世侠影': '7373508'}, {'千秋': '7502025'}, {'绝品神医': '7887195'}, {'重生天才小医女': '7380353'}, {'逆界至尊': '7923262'}, {'重生之仙帝赘婿': '7949140'}, {'农家官夫人': '7928031'}, {'末世之异兽崛起': '7903380'}, {'超能狂兵': '7871998'}, {'神武剑尊': '6802438'}, {'苍茫之尊': '7834257'}, {'万道至尊': '7870700'}, {'悍妻当道：财神娘子升职记': '7898889'}, {'修仙是要用脑子的': '7923418'}, {'农门辣媳：撩个秀才来发家': '7829868'}, {'重生之仙道狂徒': '7850815'}, {'妃来横祸：王爷的首富嫡妻': '7863129'}, {'田园医女：盛世荣宠': '7947347'}, {'重生之神医帝尊': '7934862'}, {'我爱你，与你无关': '7923435'}, {'冥界诞生': '7846775'}, {'九星机神': '7924522'}, {'萌妻出没:总裁大人请绕道': '7323790'}, {'锦绣田园：钓个相公来种田': '7792808'}, {'都市至尊神医': '7847199'}, {'农门医女：王爷娇宠田园妻': '7430478'}, {'娇女田间笑': '7859104'}, {'神厨狂妃：空间在手夫君我有': '7921255'}, {'西游之朕的大唐有属性': '7901861'}, {'巨星重生手札': '6708059'}, {'空间医女：带个包子来种田': '7875258'}, {'偷心房客俏房东': '7825336'}, {'都市梵天劫': '7397055'}, {'闪婚厚爱：纪少，轻点宠': '7865844'}, {'开个宝箱当武神': '7928032'}, {'开挂神医': '7723732'}, {'花都圣手': '7646671'}, {'都市之潜龙': '7871489'}, {'龙游花都': '7829349'}, {'混世兵王': '7431627'}, {'凤唳九天：将军夫人v5！': '7885277'}, {'魔种魔': '7416415'}, {'绝命娘子：夫君别怕，到我身后来': '7830697'}, {'武破九霄': '7787144'}, {'农家小厨娘：想吃肉来偿': '7940412'}, {'超级无敌召唤系统': '7903382'}, {'田园蜜宠：将军的小农妻': '7809943'}, {'男票每天都嫌命太长': '7894343'}, {'兽世娇宠：种种田生生崽': '7874393'}, {'重生之潇洒走一回': '7882933'}, {'都市之超强赘婿': '7945004'}, {'送给编辑的一封情书': '7847771'}, {'最强保镖': '6919029'}, {'皇后的生存法则': '7788158'}, {'废材逆天：至尊倾城九小姐': '7833966'}, {'太古圣尊': '7522178'}, {'快穿之系统教我当霸总': '7850327'}, {'嫡女在上': '7451865'}, {'重生第一宠妃': '7797143'}, {'物种心愿事务所': '7944335'}, {'进化武器': '7210711'}, {'透视小包工头': '7506862'}, {'乡村美女图': '7034781'}, {'我是超级富二代': '7940895'}, {'智能影后：影帝追妻100分': '7829341'}, {'撩妹兵王在都市': '6967760'}, {'穿行异界去淘金': '7947325'}, {'暗牌': '7933624'}, {'周老四的奋斗元年': '7927614'}, {'都市之最强狂婿': '7933707'}, {'重生之极品人生': '7643123'}, {'撩夫狂魔：娘子猛如虎': '7838986'}, {'系统种田：美味小厨娘': '7944548'}, {'上苍物语': '7885748'}, {'吻上瘾：少帅，夫人要离婚': '7842174'}, {'最强狂兵': '5123804'}, {'幺女有灵泉': '7867020'}, {'重生88:旺家小商女': '7794726'}, {'农门娇妻：家养暖夫致富记': '7830988'}, {'系统，这是你掉的节操吗': '7516224'}, {'绝世武神': '7542509'}, {'提亲记': '7169109'}, {'重生八零，媳妇有点甜': '7503234'}, {'惊华嫡女': '7447343'}, {'总裁大人笑一下': '7934622'}, {'闯仙坟': '7887381'}, {'田园医女之将军轻点宠': '7909270'}, {'噬骨之井': '7900789'}, {'盛宠隐婚妻：爹地，妈咪又怀了': '7797287'}, {'医女重生：少帅夫人要爬墙': '7893498'}, {'怎么那么甜': '7883567'}, {'绝世神皇': '7894049'}, {'逆问苍穹': '5135883'}, {'极品万事屋': '7870959'}, {'都市之逆天修仙': '7813783'}, {'鬼谷玄阵': '5306129'}, {'农女掌家：空间在手好致富': '7179248'}, {'重生九零：丑小鸭致富记': '7802566'}, {'苍天印': '7789882'}, {'三界朋友圈': '7808957'}, {'农门商女：种田撩夫两手忙': '7903125'}, {'重生之绝世仙尊': '7823306'}, {'封天仙帝': '7910891'}, {'漫漫余生我爱你': '7808440'}, {'重生八零：上山下乡致富忙': '7854936'}, {'重生之最强赘婿': '7921249'}, {'天煞帝女': '7104214'}, {'天下第一俏媒婆': '7847334'}, {'首辅的养家小丫鬟': '7847534'}, {'农家幺女致富记': '7916605'}, {'邪王心尖宠：狂妃拽上天': '7835498'}, {'最强小农民': '7913046'}, {'熊猫道长': '7843053'}, {'农门长姐': '7846400'}, {'美味萌妃：太子吃上瘾': '7911931'}, {'盛世医妃': '7948488'}, {'玄道至尊': '7948788'}, {'大明双龙录': '7940886'}, {'大唐极品赘婿': '7949568'}, {'玄境战记': '7949498'}, {'回到古代来圈粉': '7005825'}, {'妙手药王': '7115565'}, {'神仙朋友圈': '6767584'}, {'凤居天下：权色谋妃': '7943956'}, {'鬼医神农': '7137410'}, {'重生七零：面厂女工巧致富': '7953169'}, {'星主沉浮': '7953934'}, {'最强都市修仙': '7791175'}, {'不死之人': '7953823'}, {'特战军魂': '7844732'}, {'秀色小娘子：这个农女有点香': '7668297'}, {'都市医道狂少': '7746818'}, {'重生娇妻轻点宠': '7790885'}, {'农家医女有点田': '7835491'}, {'白与黑': '7824000'}, {'恐怖屋之食中忌': '7940415'}, {'邪王嗜宠：逆天毒医大小姐': '7899727'}, {'傲娇系统：农家悍女好种田': '7943934'}, {'总有逆徒想杀我': '7918189'}, {'重生之超凡赘婿': '7928049'}, {'大明驴爵爷': '7928649'}, {'蛮尊': '7918196'}, {'福满田园：王爷盛宠俏医妃': '7944747'}, {'都市之逆天邪君': '7948157'}, {'绝世狂妃：魔帝的特工妻': '7885002'}, {'绝世武帝': '7847476'}, {'奇门医术': '7952236'}, {'都市之冥王归来': '7865465'}, {'道蝉': '7471301'}, {'创世重生': '7952145'}, {'原界': '7703264'}, {'田园小娘子：将军大人的农门妻': '7843733'}, {'亚魔纪之黑石龙王': '7952290'}, {'龙霸天帝': '7922939'}, {'冥夜剑神': '6767537'}, {'摄政王的纨绔继妃': '7802537'}, {'重生七零有点甜': '7445428'}, {'喜当娘：山里汉宠妻无度': '7910127'}, {'重生之修真高手': '7929367'}, {'穿越农门：杀手娘子也种田': '7498608'}, {'重生农女的锦绣田园': '7421789'}, {'重回1985：麻辣俏媳妇': '7469035'}, {'嫡女谋：覆世卿颜': '7103564'}, {'至尊女帝：妖孽殿下，请止步': '7926725'}, {'最强大富翁': '7841307'}, {'圣女嫁到：将军速来接驾': '7909286'}, {'最强剑胚': '7846662'}, {'龙神归来': '7102394'}, {'太后摄政攻略': '7865233'}, {'最强狂婿': '7938577'}, {'武驭苍穹': '7692623'}, {'系统之最强王者': '7891177'}, {'狂宠追妻：总裁爹地有点猛': '7872111'}, {'诸天纪': '6756593'}]
    for i in book_list:
        if bookname in i.keys():
            return i[bookname]
    return False
      
        
if __name__=="__main__":
    user_agent=[
    "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50",
    "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50",
    "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0",
    "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729; InfoPath.3; rv:11.0) like Gecko",
    "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",
    "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)",
    "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)",
    "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)",
    "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1",
    "Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1",
    "Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11",
    "Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11",
    "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_0) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11",
    "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)",
    "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)",
    "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)",
    "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)",
    "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; SE 2.X MetaSr 1.0; SE 2.X MetaSr 1.0; .NET CLR 2.0.50727; SE 2.X MetaSr 1.0)",
    "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)",
    "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)",
    "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)",
    "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5",
    "Mozilla/5.0 (iPod; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5",
    "Mozilla/5.0 (iPad; U; CPU OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5",
    "Mozilla/5.0 (Linux; U; Android 2.3.7; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1",
    "MQQBrowser/26 Mozilla/5.0 (Linux; U; Android 2.3.7; zh-cn; MB200 Build/GRJ22; CyanogenMod-7) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1",
    "Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10",
    "Mozilla/5.0 (Linux; U; Android 3.0; en-us; Xoom Build/HRI39) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13",
    "Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.337 Mobile Safari/534.1+",
    "Mozilla/5.0 (hp-tablet; Linux; hpwOS/3.0.0; U; en-US) AppleWebKit/534.6 (KHTML, like Gecko) wOSBrowser/233.70 Safari/534.6 TouchPad/1.0",
    "Mozilla/5.0 (SymbianOS/9.4; Series60/5.0 NokiaN97-1/20.0.019; Profile/MIDP-2.1 Configuration/CLDC-1.1) AppleWebKit/525 (KHTML, like Gecko) BrowserNG/7.1.18124",
    "Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)",
    "UCWEB7.0.2.37/28/999",
    "NOKIA5700/ UCWEB7.0.2.37/28/999",
    "Openwave/ UCWEB7.0.2.37/28/999",
    "Mozilla/4.0 (compatible; MSIE 6.0; ) Opera/UCWEB7.0.2.37/28/999",
     # iPhone 6：
    "Mozilla/6.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/8.0 Mobile/10A5376e Safari/8536.25", 
]
    bookname=input("请输入需要下载的书名：")
    bookid=get_bookid(bookname)
    if bookid:
        print("你想要的书已经找到！开始下载。。。")
        download=Book(bookid)
        book_info=download.get_json()
        chapter_list,book_Name=download.parse_info(book_info)
        with open('test.js','r',encoding='UTF-8') as f:
            js=f.read()
        #print(js)
        ctx=execjs.compile(js)
        with open('{}.txt'.format(book_Name),'w') as f:
            for chapter in chapter_list:
                if chapter['chapterPrice']==0:
                    chapter_name=chapter['chapterName']
                    encrypt_content=download.get_content(chapter['chapterUrlSuffix'])
                    if encrypt_content:
                        chapter_content=ctx.call('_decodeCont',encrypt_content).replace('<br/>','\n')                        
                        f.write('\n---------------章节分界线--------------\n'+chapter_name)
                        f.write(chapter_content)
                   
                else:
                    print('该章节开始是付费文章，无法继续下载！')
                    break
        print('{}全书已经下载完毕！'.format(book_Name))
    else:
        print("你想要的书暂时无法找到！")
            